export default {
    data() {
        return {

        }
    },
    methods: {
        //通过腾讯地图的API获取GEO数据
        getTencentGeocoder(longitude, latitude) {
            return new Promise((resolve, reject) => {
                uni.request({
                    url: `https://apis.map.qq.com/ws/geocoder/v1/?location=${latitude},${longitude}&key=${this.$config.tencentMapkey}`,
                    method: 'GET',
                    success: res => {
                        var geodata = res.data;
                        if (geodata.status != 0) {
                            reject({
                                code: 3,
                                msg: `获取失败,${geodata.status}`
                            });
                            return;
                        }
                        resolve({
                            code: 1,
                            msg: '',
                            data: {
                                longitude: longitude,
                                latitude: latitude,
                                address: geodata.result.formatted_addresses.recommend ||
                                    geodata.result.address,
                                province: geodata.result
                                    .address_component.province,
                                city: geodata.result.address_component
                                    .city,
                                country: geodata.result
                                    .address_component.district,
                                countryId: geodata.result.ad_info.adcode,
                                town: geodata.result.address_component
                                    .town || geodata.result.address_reference.town.title,
                                townId: geodata.result.address_reference.town.id + '000',
                                street: geodata.result.address_component
                                    .street
                            }
                        })
                    },
                    fail: error => {
                        reject({
                            code: 3,
                            msg: '获取位置信息失败'
                        })
                    }
                });
            })
        }
    }
}
